<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="预约管理">
    <meta name="keywords" content="预约列表">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }

        .el-input__inner {
            width: 180px;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>检查项管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <template>
                    <div class="block">
                        <el-date-picker v-model="dateRange"
                                        type="daterange"
                                        align="right"
                                        unlink-panels
                                        range-separator="至"
                                        start-placeholder="开始日期"
                                        end-placeholder="结束日期"
                                        :picker-options="pickerOptions">
                        </el-date-picker>
                        <el-select v-model="orderType" placeholder="预约类型">
                            <el-option value="微信预约">
                                微信预约
                            </el-option>
                            <el-option value="电话预约">
                                电话预约
                            </el-option>
                            <el-option value="">
                                无要求
                            </el-option>
                        </el-select>
                        <el-select v-model="orderStatus" placeholder="预约状态">
                            <el-option value="未到诊">
                                未到诊
                            </el-option>
                            <el-option value="已到诊">
                                已到诊
                            </el-option>
                            <el-option value="">
                                无要求
                            </el-option>
                        </el-select>
                        <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                                  class="filter-item"></el-input>
                        <br/>
                        <br/>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button @click="refreshPage()" class="dalfBut">刷新</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">预约</el-button>
                    </div>
                </template>


            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号" width="50"></el-table-column>
                <el-table-column prop="orderDate"  sortable label="预约日期" align="center"></el-table-column>
                <!--<el-table-column prop="orderAddress" label="预约地址" align="center"></el-table-column>-->
                <el-table-column prop="name" label="姓名" align="center" width="60"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号" align="center" width="100"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="setmeal" label="套餐名称" align="center" width="200"></el-table-column>
                <el-table-column label="预约状态" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.orderStatus == '未到诊' ? '未到诊' : '已完成'}}</span>
                        <el-switch v-model="scope.row.orderStatus"
                                   @change="changeOrderStatus(scope.row.id)"
                                   active-value="未到诊"
                                   inactive-value="已到诊"
                                   active-color="#13ce66"
                                   inactive-color="#ff4949">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column label="预约操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <!--                                        <el-col :span="12">
                                                                                    <el-form-item label="婚姻状态">
                                                                                        <el-select v-model="formData.marriyStatus">
                                                                                            <el-option label="未婚" value="0"></el-option>
                                                                                            <el-option label="已婚" value="1"></el-option>
                                                                                        </el-select>
                                                                                    </el-form-item>
                                                                                </el-col>-->
                                        <el-col :span="12">
                                            <el-form-item label="预约时间">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <el-table
                                            ref="multipleTable"
                                            size="small"
                                            :data="tableData"
                                            tooltip-effect="dark"
                                            current-row-key="id"
                                            style="width: 100%">
                                        <el-table-column
                                                label="选择"
                                                align="center"
                                                width="55">
                                            <template scope="scope">
                                                <el-radio :label="scope.$index" v-model="radio"
                                                          @change.native="getCurrentRow(scope.row)">&nbsp;</el-radio>
                                            </template>
                                        </el-table-column>
                                        <el-table-column
                                                align="center"
                                                prop="name"
                                                label="套餐名称"
                                                width="120">
                                        </el-table-column>
                                        <el-table-column
                                                align="center"
                                                label="适用人群"
                                                width="120">
                                            <template slot-scope="scope">
                                                <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column
                                                align="center"
                                                prop="remark"
                                                label="套餐说明"
                                                width="120">
                                        </el-table-column>
                                    </el-table>
                                    <!-- <table class="datatable">
                                         <thead>
                                         <tr>
                                             <th>选择</th>
                                             <th>套餐名称</th>
                                             <th>适用人群</th>
                                             <th>套餐介绍</th>
                                         </tr>
                                         </thead>
                                         <tbody>
                                         <form name="space">
                                             <tr v-for="c in tableData">

                                                 <td>
                                                     <input :id="c.id" v-model="setmealIds" type="checkbox"
                                                            :value="c.id">
                                                 </td>
                                                 <td><label :for="c.id">{{c.name}}</label></td>
                                                 <td><label :for="c.id">
                                                     {{ c.sex == '0' ? '不限' : c.sex == '1' ? '男' : '女'}}
                                                 </label></td>
                                                 <td><label :for="c.id">{{c.remark}}</label></td>
                                             </tr>
                                         </form>
                                         </tbody>
                                     </table>-->
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <div class="add-form">
                <el-dialog title="编辑预约" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="婚姻状态">
                                                <el-select v-model="formData.marriyStatus">
                                                    <el-option label="未婚" value="0"></el-option>
                                                    <el-option label="已婚" value="1"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约时间">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <el-table
                                            size="small"
                                            :data="tableData"
                                            tooltip-effect="dark"
                                            current-row-key="id"
                                            style="width: 100%">
                                        <el-table-column
                                                type="selection"
                                                width="55">
                                        </el-table-column>
                                        <el-table-column
                                                prop="name"
                                                label="套餐名称"
                                                width="120">
                                        </el-table-column>
                                        <el-table-column
                                                label="适用人群"
                                                width="120">
                                            <template slot-scope="scope">
                                                <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column
                                                prop="remark"
                                                label="套餐说明"
                                                width="120">
                                        </el-table-column>
                                    </el-table>

                                    <!-- <table class="datatable">
                                         <thead>
                                         <tr>
                                             <th>选择</th>
                                             <th>套餐名称</th>
                                             <th>适用人群</th>
                                             <th>套餐介绍</th>
                                         </tr>
                                         </thead>
                                         <tbody>
                                         <tr v-for="c in tableData">
                                             <td>
                                                 <input :id="c.id" v-model="setmealIds"  type="checkbox" :value="c.id">
                                             </td>
                                             <td><label :for="c.id">{{c.name}}</label></td>
                                             <td><label :for="c.id">
                                                 {{ c.sex == '0' ? '不限' : c.sex == '1' ? '男' : '女'}}
                                             </label></td>

                                             <td><label :for="c.id">{{c.remark}}</label></td>
                                         </tr>
                                         </tbody>
                                     </table>-->
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>


        </div>
    </div>
</div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pickerOptions: {
                shortcuts: [{
                    text: '本月',
                    onClick(picker) {
                        picker.$emit('pick', [new Date(), new Date()]);
                    }
                }, {
                    text: '今年至今',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date(new Date().getFullYear(), 0);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近六个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setMonth(start.getMonth() - 6);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            dateRange: '',
            orderType: '',
            orderStatus: '',
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null //查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            tableData: [],//添加表单窗口中套餐数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            setmealIds: [],//添加表单窗口中套餐复选框对应id
            templateSelection: {},
            radio: '',
            rules: {//校验规则
                phoneNumber: [
                    {required: true, message: '手机号码为必填项', trigger: 'blur'},
                    {min: 11, max: 11, message: '请输入11位手机号码', trigger: 'blur'},
                    {
                        pattern: /^(0|86|17951)?(13[0-9]|15[012356789]|17[3678]|18[0-9]|14[57])[0-9]{8}$/,
                        message: '请输入正确的手机号码'
                    }
                ],
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                idCard: [
                    {required: true, message: '请输入证件号', trigger: 'blur'},
                    {
                        pattern: /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/,
                        message: '请输入正确的身份证号'
                    }
                ]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //刷新
            refreshPage() {
                this.dateRange = '';
                this.orderType = '';
                this.orderStatus = '';
                this.pagination.queryString = '';
                this.findPage();
            },
            //编辑
            handleEdit() {
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {

                    } else {
                        this.$message.error("表单数据校验失败!");
                        return false;
                    }
                });
            },
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
            //添加
            handleAdd() {
                if(this.formData.birthday!=null&& this.formData.birthday!=''){
                    var bDate=this.formData.birthday;
                    var oDate=this.formData.orderDate;
                    var birthdayDate=bDate.getFullYear() + "-" + (bDate.getMonth() + 1) + "-" + bDate.getDate();
                    var orderDate=oDate.getFullYear() + "-" + (oDate.getMonth() + 1) + "-" + oDate.getDate();
                    var param ={
                        name:this.formData.name,
                        idCard:this.formData.idCard,
                        birthday:birthdayDate,
                        phoneNumber: this.formData.phoneNumber,
                        sex:this.formData.sex,
                        age:this.formData.age,
                        orderDate:orderDate
                    }
                }else{
                    var oDate=this.formData.orderDate;
                    var orderDate=oDate.getFullYear() + "-" + (oDate.getMonth() + 1) + "-" + oDate.getDate();
                    var param ={
                        name:this.formData.name,
                        idCard:this.formData.idCard,
                        phoneNumber: this.formData.phoneNumber,
                        sex:this.formData.sex,
                        age:this.formData.age,
                        orderDate:orderDate
                    }
                }
                axios.post("/orderSetting/addOrderSettingList/" + this.templateSelection.id, param).then((res) => {
                    this.dialogFormVisible = false;
                    if (res.data.flag) {
                        //执行成功
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        //执行失败
                        this.$message.error(res.data.message);
                    }
                }).finally(() => {
                    this.findPage();
                });
            },
            //分页查询
            //分页查询
            findPage() {
                if (this.dateRange != null && this.dateRange != '') {
                    var start = this.dateRange[0];
                    var end = this.dateRange[1];
                    var sDate = start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate();
                    var eDate = end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + end.getDate();
                    var param = {
                        //当前页码
                        currentPage: this.pagination.currentPage,
                        //显示数量
                        pageSize: this.pagination.pageSize,
                        //查询字段
                        queryString: this.pagination.queryString,
                        //起始查询日期
                        startDate: sDate,
                        //结束查询日期
                        endDate: eDate,
                        //预约类型
                        orderType: this.orderType,
                        //预约状态
                        orderStatus: this.orderStatus
                    }
                } else {
                    var param = {
                        //当前页码
                        currentPage: this.pagination.currentPage,
                        //显示数量
                        pageSize: this.pagination.pageSize,
                        //查询字段
                        queryString: this.pagination.queryString,
                        //预约类型
                        orderType: this.orderType,
                        //预约状态
                        orderStatus: this.orderStatus
                    }
                }
                axios.post("/orderSettingList/findPage.do", param).then((res) => {
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.activeName = 'first';
                this.setmealIds = [];
            },
            // 弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm();
                axios.post("/setMeal/findAll").then((res) => {
                    this.tableData = res.data.data;
                });
            },
            // 确定预约
            handleUpdate(row) {
                this.$confirm("确定预约后将会以短信的方式通知客户具体体检时间，是否确定?", "提示", {
                    type: 'warning'
                }).then(() => {
                    axios.post("/localOrder/notification.do?phoneNumber=" + row.phoneNumber + "&orderDate=" + row.orderDate).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            });
                            this.findPage();
                        } else {
                            // this.$message.error("执行失败");
                            this.$message({
                                type: 'fail',
                                message: res.data.message
                            });
                        }
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    })
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm("数据删除后将无法回复，请确认是否删除?", "提示", {
                    type: 'warning'
                }).then(() => {
                    axios.post("/localOrder/deleteOrderById.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        } else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r) => {
                        if (r == 'Error: Request failed with status code 403') {
                            //权限不足
                            this.$message.error('无访问权限');
                            return;
                        } else {
                            this.$message.error('未知错误');
                            return;
                        }
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    })
                });
            },
            changeOrderStatus(id) {
                axios.get("/orderSettingList/changeOrderStatus.do?id="+id).then((res) => {
                    if (res.data.flag) {
                        this.$message.success(res.data.message);
                    } else {
                        this.$message.error(res.data.message);
                    }
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            },
            getCurrentRow(row) {
                this.templateSelection = row;
            }
        }
    })
</script>
</html>